% Note: ret=diff(cds)==> yields returns. This gives a lot of NaN due to
% differences in time-series lenght of each firm. So, I need
% ret(isnan(ret))=0; to get ri of NaN and make them 0. Then delete the last
% 0 when estimating RV and Jumps

% Prepare data for Pooled regression

 y = 1;
 for i = 0:21.35185:116600000
 av_c(y,: ) = mean(c(i+1:i+21.35185,:)); % v - r.volatilty, not anualized and scaled.
 y=y+1;
 end

% vola = reshape(e,[],1);
% ------------------------------------------------------------------------
% average weeky RVJ/RVC (RVJ and RVC are daily- I need them weekly)
% ------------------------------------------------------------------------

y = 1;
for i = 0:13:75240
d_zmcp(y,: ) = mean(zmcp_tj(i+1:i+13,:)); % j - r.jump, not anualized and scaled
y=y+1;
end
y = 1;
for i = 0:65:75240
w_zmcp(y,: ) = mean(zmcp_tj(i+1:i+65,:)); % j - r.jump, not anualized and scaled
y=y+1;
end
y = 1;
for i = 0:286:75240
m_zmcp(y,: ) = mean(zmcp_tj(i+1:i+286,:)); % j - r.jump, not anualized and scaled
y=y+1;
end
clear ('y','i');
y = 1;
for i = 0:13:75240
d_zmcp(y,: ) = mean(zmcp_tj(i+1:i+13,:)); % j - r.jump, not anualized and scaled
y=y+1;
end

y = 1;
for i = 0:65:75240
w_zmcp(y,: ) = mean(zmcp_tj(i+1:i+65,:)); % j - r.jump, not anualized and scaled
y=y+1;
end
clear ('y','i');
y = 1;
for i = 0:286:15470
m_zmcp(y,: ) = mean(zmcp_tj(i+1:i+286,:)); % j - r.jump, not anualized and scaled
y=y+1;
end
% ------------------------------------------------------------------------
% get he data ready for STATA
% ------------------------------------------------------------------------
daily_zmcp2 = repmat(d_zmcp,88,1);
weekly_zmcp2 = repmat(w_zmcp,88,1);
monthly_zmcp2 = repmat(m_zmcp,88,1);
skew_d = reshape(skew_d_2,[],1);
skew_w = reshape(skew_w_2,[],1);
skew_m = reshape(skew_m_2,[],1);
kurt_d = reshape(kurt_d_2,[],1);
kurt_w = reshape(kurt_w_2,[],1);
kurt_m = reshape(kurt_m_2,[],1);
% ------------------------------------------------------------------------
% This is my hostorical volatility and kurtosis from daily returns I need
% to estimate returns from daily data (download again for a year ahead of
% my starting sampling period
% ------------------------------------------------------------------------
y = 1;
for i = 0:250:883
ww(y,: ) = kurtosis(Return(i+1:i+250,:)); % j - r.jump, not anualized and scaled
y=y+1;
end

y = 1;
for i = 0:250:883
sk(y,: ) = skewness(Return(i+1:i+250,:)); % j - r.jump, not anualized and scaled
y=y+1;
end

% This coppy quarterly leverage data for each month

B = repelem(A, 4, 1);
